<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tfFormElement
 *
 * @author waterfrog
 */
if(!defined('TinyFW')) exit('Access denied!');

class tfFormElement {
   
    private $_name  =   null;
    private $_id    =   null;
    private $_value =   null;
    private $_caption   =   null;
    
    //the attribute of the element
    private $_attr   =   array();

    public function  __construct() {
        
    }

    public function setName($name) {
        $this->_name = $name;
    }

    public function getName() {
        return $this->_name;
    }

    public function setId($id) {
        $this->_id = $id;
    }

    public function getId(){
        return $this->_id;
    }

    public function setValue($value) {
        $this->_value = $value;
    }

    public function getValue() {
        return $this->_value;
    }

    public function setAttr($attr, $value='') {
        if(is_array($attr)) {
            foreach($attr as $k => $v) {
                $this->_attr[$k] = $v;
            }
        } else {
            $this->_attr[$attr] = $value;
        }

    }

    public function getAttr() {
        return $this->_attr;
    }

    public function getAttrStr() {
        if(empty($this->_attr)) {
            return "";
        } else {
            $ret = "";
            foreach($this->_attr as $k => $v) {
                $ret .=  " " . $k . "=" . $v. " ";
            }
            return $ret;
        }
    }

    public function setCaption($caption) {
        if(empty($caption)) {
            $this->_caption = $this->getName();
        } else {
            $this->_caption = $caption;
        }
    }

    public function getCaption() {
        return $this->_caption;
    }

    public function isHidden() {
        return false;
    }

    public function isContainer() {
        return false;
    }

    //display the element, implemented by each child class
    public function render() {
        
    }

    public function  __toString() {
        return $this->render();
    }
    

}
?>
